
#include <iostream>
#include "MenuComp.h"
#include "CONST.h"

int MenuComp::checkType(int id) {
    if(childen[id]->getchilden().empty()){
        return childen[id].operator->()->checkType(id);
    }

    childen[id]->show();
    return ISNODE;
}

void MenuComp::show() {
    std::cout<<desc<<std::endl;
    std::cout<<"-----------"<<std::endl;
    for(int i=0;i!=childen.size();++i){
        childen[i].operator->()->print(i);
    }
}

std::vector<std::shared_ptr<IMenuComponent>> MenuComp::getchilden() {
    return childen;
}

void MenuComp::add(IMenuComponent * items) {
    childen.emplace_back(items);
}

void MenuComp::setText(const std::string & text) {
    this->text="+ "+text;

}

void MenuComp::setDesc(const std::string & desc) {
    this->desc=desc;

}

void MenuComp::print(long id) {
    std::cout<<id<<" "<<text<<std::endl;

}

